function get_highest_zIndex(){
    var elements = document.getElementsByTagName("*");
    var highest_index = 0;

    for (var i = 0; i < elements.length - 1; i++) {
        if (parseInt(elements[i].style.zIndex) > highest_index) {
            highest_index = parseInt(elements[i].style.zIndex);
        }
    }
    return highest_index;
}
function session_expired_test(json_return_message){
    //testa  se a sessao esta expirada
    try{
       var json = JSON.parse(json_return_message);
       if(json.redirect == true){
           alert("Sessão Expirada!");
           window.location.reload();
       }
    }catch(e){}
}    
function str_replace(chars,repls,str) {
	if (chars instanceof Array) {
		var arrString = new Array();
		for (i=0; i<chars.length; i++) {
			 var count = i-1;
			 if (i>0) {
				 arrString.push(arrString[count].replace(chars[i],repls[i]));
			 } else {
				 arrString.push(str.replace(chars[i],repls[i]));
			 }
		}
		string = arrString.pop();
	} else {
		string = str.replace(chars,repls);
	}
	return string;
}

function validateNumericField(field_id){
	var number = $('#'+field_id).val();
	if(""==number){
		$("#submit_chart_button").attr("disabled", "disabled");
		return;
	}
	if(isNaN(number) || 1>number){
		alert('{__ t = "You must enter a positive integer in this field."}');
		alert('You must enter a positive integer in this field.');
		$("#submit_chart_button").attr("disabled", "disabled");
	}else{
		$("#submit_chart_button").removeAttr("disabled");
	}
}
function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}
function objToString (obj) {
    var str = '';
    for (var p in obj) {
        if (obj.hasOwnProperty(p)) {
            str += p + '::' + obj[p] + '\n';
        }
    }
    return str;
}
function get_random_color() {
    var letters = '0123456789ABCDEF'.split('');
    var color = '#';
    for (var i = 0; i < 6; i++ ) {
        color += letters[Math.round(Math.random() * 15)];
    }
    return color;
}
function number_format (number, decimals, dec_point, thousands_sep) {
	number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
    var n = !isFinite(+number) ? 0 : +number,
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);return '' + Math.round(n * k) / k;
        };
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');}
    return s.join(dec);
}